#!/usr/bin/env python3

import os.path
import argparse

from constants import DIR


ap = argparse.ArgumentParser()
ap.add_argument('-u', action='store', type=str,
                dest='url', help='start point url')
ap.add_argument('-d', action='store', type=int,
                dest='depth', help='depth', default=2)
ap.add_argument('-l', action='store', type=int,
                dest='level', help='log level', default=4)
ap.add_argument('-f', action='store', type=str,
                dest='logfile', help='log file')
ap.add_argument('--thread', action='store', type=int,
                dest='nthreads', help='number of threads', default=20)
ap.add_argument('--dbfile', action='store', type=str,
                dest='dbfile', help='sqlite database, :memory: as default',
                default=':memory:')
ap.add_argument('--key', action='store', type=str,
                dest='key', help='key word')
ap.add_argument('--testself', action='store_true',
                dest='testself', help='do self test', default=False)


def parse_args(args):
    opts = ap.parse_args(args)
    if opts.dbfile != ':memory:':
        opts.dbfile = os.path.join(DIR, opts.dbfile)
    return opts
